home *** CD-ROM | disk | FTP | other *** search
- PROGRAM STF; { Filter Input File to DOS Standard Text Format file }
-
- {======================================================================}
- { }
- { STF.PAS A DOS filter to convert files to Standard Text Format }
- { }
- { Version: 1.0 20OCT84 Turbo Pascal }
- { }
- { Author: Joseph E. Doran, Jr. }
- { 145 Indian Hill Road }
- { Carlisle, MA 01741 }
- { (617) 369-9312 }
- { }
- { Usage: STF <A:MESSY.DAT >B:STANDARD.TXT }
- { (Refer to the DOS manual for a discussion }
- { of filters.) }
- { }
- {======================================================================}
-
- CONST
- MaxLen = 254; { maximum output record length }
- EOF = ^Z; { end-of-file marker; ctrl-Z }
- EOL = ^M^J; { end-of-line marker; carriage-return, line-feed }
-
- TYPE
- str255 = string[255];
-
- VAR
- StdBuffer, TxtBuffer: str255;
- StdLength, StdByte, StdPos, TxtPos, TabStop, i: integer;
-
-
- PROCEDURE StdRead(Var StdData:Str255); { Read from Standard Input }
-
- TYPE
- register = record
- ax,bx,cx,dx,bp,si,di,ds,es,flags: integer;
- END;
-
- VAR
- IntrArgs: register;
- StdLen: byte absolute StdData;
-
- BEGIN
- WITH IntrArgs do
- BEGIN
- ax := $3F00;
- bx := 0;
- cx := 255;
- ds := seg(StdData);
- dx := ofs(StdData) + 1;
- Intr($21,IntrArgs);
- StdLen := ax;
- END;
- END;
-
-
- PROCEDURE StdWrite(StdData:Str255); { Write to Standard Output }
-
- TYPE
- register = record
- ax,bx,cx,dx,bp,si,di,ds,es,flags: integer;
- END;
-
- VAR
- IntrArgs: register;
-
- BEGIN
- WITH IntrArgs do
- BEGIN
- ax := $4000;
- bx := 1;
- cx := length(StdData);
- ds := seg(StdData);
- dx := ofs(StdData) + 1;
- Intr($21,IntrArgs);
- END;
- END;
-
-
- PROCEDURE ASCGraph; { Process standard ASCII graphic characters }
-
- BEGIN
- TxtPos := TxtPos + 1;
- If TxtPos > MaxLen then
- BEGIN
- StdWrite(copy(TxtBuffer,1,MaxLen)+EOL);
- TxtPos := 1;
- END;
- TxtBuffer[TxtPos] := chr(StdByte);
- END;
-
-
- PROCEDURE HrzPaper; { Simulate horizontal paper motion }
-
- BEGIN
- If StdByte in [8,127] then { BS and DEL backspaces }
- BEGIN
- If TxtPos > 0 then TxtPos := TxtPos - 1;
- END;
- If StdByte = 9 then { HT horizontal tab every eight spaces }
- BEGIN
- TabStop := (TxtPos div 8) * 8 + 8;
- If TabStop > MaxLen then TabStop := MaxLen;
- If TabStop > TxtPos then
- BEGIN
- For i := TxtPos + 1 to TabStop do TxtBuffer[i] := ' ';
- END;
- TxtPos := TabStop;
- END;
- END;
-
-
- PROCEDURE VrtPaper; { Simulate vertical paper motion }
-
- BEGIN
- If StdByte = 10 then { LF line-feed }
- BEGIN
- If TxtPos > 0 then StdWrite(copy(TxtBuffer,1,TxtPos));
- StdWrite(EOL);
- END;
- If StdByte = 11 then { VT vertical tab }
- BEGIN
- If TxtPos > 0 then StdWrite(copy(TxtBuffer,1,TxtPos));
- StdWrite(EOL+EOL+EOL);
- END;
- If StdByte = 12 then { FF form feed }
- BEGIN
- If TxtPos > 0 then StdWrite(copy(TxtBuffer,1,TxtPos));
- StdWrite(EOL+'.pa'+EOL);
- END;
- TxtPos := 0;
- END;
-
-
- PROCEDURE StdPurge; { Purge miscellaneous control characters }
-
- BEGIN
- END;
-
-
- BEGIN { Mainline Processing }
-
- { create output text buffer }
-
- TxtPos := 0;
- TxtBuffer := '';
- For i := 1 to MaxLen do TxtBuffer := TxtBuffer+'X';
-
- { read/filter/write loop }
-
- Repeat
- StdRead(StdBuffer);
- StdLength := length(StdBuffer);
- For StdPos := 1 to StdLength do
- BEGIN
- StdByte := ord(StdBuffer[StdPos]) and 127;
- Case StdByte of
- 0..7: StdPurge;
- 8..9: HrzPaper;
- 10..12: VrtPaper;
- 13..31: StdPurge;
- 32..126: ASCGraph;
- 127: HrzPaper;
- END;
- END;
- Until StdLength = 0;
-
- { flush last text buffer to output }
-
- If TxtPos > 0 then StdWrite(copy(TxtBuffer,1,TxtPos)+EOL);
-
- { write end-of-file marker }
-
- StdWrite(EOF);
-
- END.
-
- *** CREATED 10/26/84 08:59:08 BY $MS ***